package com.jyw.business.de.domain.vo.web;

import com.alibaba.fastjson2.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.jyw.business.de.constant.DemandProcessConstant;
import com.jyw.business.de.constant.TaskProcessConstant;
import com.jyw.business.de.domain.DeDemandProcess;
import com.jyw.business.de.domain.DeTaskProcess;
import com.jyw.common.annotation.Conversion;
import com.jyw.common.constant.SysDictTypeConstant;
import com.jyw.common.enums.ConversionType;
import com.jyw.common.utils.DictUtils;
import com.jyw.common.utils.bean.BeanUtils;
import com.jyw.system.utils.UserUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;

import java.util.Date;

@ApiModel("任务流程返回实体")
@Data
@FieldNameConstants
@NoArgsConstructor
public class TaskProcessVO {

    @ApiModelProperty("操作记录id")
    private Long id;

    /** 需求id */
    @ApiModelProperty("任务id")
    private Long taskId;

    /** 操作类型（数据字典） */
    @ApiModelProperty("操作类型（数据字典）")
    @Conversion(value = ConversionType.DICT,dictType = SysDictTypeConstant.DE_TASK_PROCESS_STATE)
    private String operState;

    @ApiModelProperty("操作类型标签")
    private String operStateToName;

    /** 参数 */
    @ApiModelProperty("参数")
    private String processValue;

    @ApiModelProperty("参数对象")
    private Object processObj;


    /** 创建人(创建人) */
    @ApiModelProperty("操作人id(创建人)")
    @Conversion(value = ConversionType.USER,name = Fields.createUserName)
    private Long createUser;

    /** 创建人(创建人) */
    @ApiModelProperty("操作人名称(创建人)")
    private String createUserName;

    /** 创建时间(创建时间) */
    @ApiModelProperty("创建时间(创建时间)")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    public TaskProcessVO(DeTaskProcess data) {
        BeanUtils.copyProperties(data,this);
        switch (data.getOperState()) {
            case TaskProcessConstant.BACK:
            case TaskProcessConstant.PAUSE:
            case TaskProcessConstant.TERMINATION:
                JSONObject json = JSONObject.parseObject(data.getProcessValue());
                setProcessObj(json);
                break;
            case TaskProcessConstant.HURRY:
                setProcessObj(data.getProcessValue());
                break;
        }
    }
}
